﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PhotoGallery.Abstract;
using PhotoGallery.Concrete;
using PhotoGallery.Entities;

namespace PhotoGallery.Controllers
{
    public class PhotoController : Controller
    {
        //
        // GET: /Category/
        private IPhotoRepository PhotoRepository;

        public PhotoController()
        {
            string connString = @"server=.\SQLEXPRESS; Integrated Security=SSPI ;database=PhotoGallery;";
            PhotoRepository = new SqlPhotoRepository(connString);
        }



         public ActionResult List(int? CategoryId)
        {
          var PhotoInCategory =  (CategoryId == null) 
              ? PhotoRepository.Photo
              : PhotoRepository.Photo.Where(p => p.CategoryId == CategoryId);

          return View(PhotoInCategory.ToList());
        }
        

        

        public FileContentResult GetSmallImage(int? PhotoId) {
            Photo photo = (from p in PhotoRepository.Photo
                           where p.PhotoId == PhotoId
                           select p).First();

            return File(photo.Image.SmallImage,photo.Image.ImageMimeType);
        }

         

        
        
    }
}
